<?php
    header('Access-Control-Allow-Origin: *');
    // header('Content-Type:text/html;charset=utf-8');
    header('Content-Type:application/json;charset=utf-8');
    $con = mysqli_connect("127.0.0.1", "root", "root", "mydb");
    $classId = $_GET['classId'];
    $signLocation = $_GET['signLocation'];
    $chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*?';
    $signPwd=substr(str_shuffle($chars),mt_rand(0,strlen($chars)-11),6);
    // echo $signPwd;
    $sql = "UPDATE lesson SET isSign = 1, signPwd = '$signPwd', sign_location='$signLocation' WHERE l_id = '$classId';";
    $res = mysqli_query($con,$sql);
    if(mysqli_affected_rows($con) > 0){
        echo json_encode(array(
            'state' => 'start',
            'signPwd' => $signPwd
        ));
    }else{
        echo json_encode(array(
            'state' => 'fail',
        ));
    }
    mysqli_close($con);
?>